package com.zhejiangzhengyuan.municipal_security.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.zhejiangzhengyuan.municipal_common.entity.dto.JurisdictionDto;
import com.zhejiangzhengyuan.municipal_common.entity.vo.JurisdictionVo;
import com.zhejiangzhengyuan.municipal_common.mapper.ActionMapper;
import com.zhejiangzhengyuan.municipal_common.response.ResponseVo;
import com.zhejiangzhengyuan.municipal_common.service.ActionService;
import com.zhejiangzhengyuan.municipal_common.utils.ConstantUtil;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author lin_ju
<<<<<<< Updated upstream
 * Create on 2019/12/24
 */
@RestController
@RequestMapping("/security/jurisdiction")
@Api(tags = "权限行为管理")
public class JurisdictionController {
    @Autowired
    private ActionService actionService;
    @Autowired
    private ActionMapper actionMapper;


    @ApiImplicitParams({@ApiImplicitParam(name = "TOKEN", value = "Authorization token", required = true, dataType = "string", paramType = "header")})
    @ApiOperation(value = "设置当前页和每页显示条数",notes = "根据当前页和每页显示条数分页查询")
    @GetMapping("/findPage")
    public ResponseVo selectJurisdictionVoByAllPage(@ApiParam("页码") Long page, @ApiParam("每页显示条数") Long limit) {
        // pageNo默认为1；size默认为15
        page = page == null || page <= 0 ? 1 : page;
        limit = limit == null || limit <= 0 ? 9 : limit;
        IPage<JurisdictionVo> jurisdictionVoIPage = actionService.selectJurisdictionVoByAllPage(page,limit);
        return jurisdictionVoIPage == null
                ? new ResponseVo<>(ConstantUtil.ResultCode.SERVER_ERROR, "没有数据")
                : new ResponseVo<>(ConstantUtil.ResultCode.SUCCESS, jurisdictionVoIPage);
    }
    @ApiOperation(value = "添加API")
    @PostMapping("/insertJurisdiction")
    public ResponseVo insertJurisdiction(@ModelAttribute JurisdictionDto jurisdictionDto) {
       int i = actionService.insertJurisdiction(jurisdictionDto);
       return i>0?
               ResponseVo.SUCCESS:
               ResponseVo.SERVER_ERROR;
    }
    @ApiOperation(value = "更新API")
    @PostMapping("/updateJurisdiction")
    public ResponseVo updateJurisdiction(@ModelAttribute JurisdictionDto jurisdictionDto) {
        int i = actionService.updateJurisdiction(jurisdictionDto);
        return i>0?
                ResponseVo.SUCCESS:
                ResponseVo.SERVER_ERROR;
    }


}
